import 'dart:ffi';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:mtf/app/data/AgreementContainEntity.dart';
import 'package:mtf/app/data/BankEntity.dart';
import 'package:mtf/app/data/BannerEntity.dart';
import 'package:mtf/app/data/ClassifyEvaluateBeanEntity.dart';
import 'package:mtf/app/data/FileEntity.dart';
import 'package:mtf/app/data/IncomeEntity.dart';
import 'package:mtf/app/data/KInfoEntity.dart';
import 'package:mtf/app/data/NewsEntity.dart';
import 'package:mtf/app/data/NoticeEntity.dart';
import 'package:mtf/app/data/QuestionEntity.dart';
import 'package:mtf/app/data/RechargeConfigEntity.dart';
import 'package:mtf/app/data/RechargeRecordEntity.dart';
import 'package:mtf/app/data/TokenBeanEntityEntity.dart';
import 'package:mtf/app/data/UsdRecordEntity.dart';
import 'package:mtf/app/data/VersionBeanEntity.dart';
import 'package:mtf/app/data/VideoEntity.dart';
import 'package:mtf/app/data/WithdrawRecordEntity.dart';
import 'package:mtf/app/data/user_info_entity.dart';
import 'package:mtf/app/net/ApiServer.dart';
import 'package:mtf/dio_util/dio_method.dart';
import 'package:mtf/dio_util/dio_response.dart';
import 'package:mtf/dio_util/dio_util.dart';

import '../data/ClassifyBeanEntity.dart';
import '../data/MoneyAccountCountEntity.dart';
import '../data/ServerEntity.dart';

class HttpManager {
  static Future<DioResponse<Void>> reqYzm(String phone, String type) async {
    return await DioUtil().request(ApiServer.POST_YZM,
        method: DioMethod.post, params: {"phone": phone, "type": type});
  }

  static Future<DioResponse<Object>> reqRegister(
      String phone, String code, String password) async {
    return await DioUtil()
        .request(ApiServer.POST_REGISTER, method: DioMethod.post, params: {
      "phone": phone,
      "code": code,
      "password": password,
    });
  }

  static Future<DioResponse<TokenBeanEntityEntity>> reqLogin(
      String phone, String password) async {
    return await DioUtil()
        .request(ApiServer.POST_LOGIN, method: DioMethod.post, params: {
      "phone": phone,
      "password": password,
    });
  }

  static Future<DioResponse<UserInfoEntity>> reqUserInfo() async {
    return await DioUtil()
        .request(ApiServer.POST_USERINFO, method: DioMethod.post);
  }

  static Future<DioResponse<BannerEntity>> reqBannerList() async {
    return await DioUtil()
        .request(ApiServer.POST_BANNER, method: DioMethod.post);
  }

  static Future<DioResponse<NoticeEntity>> reqNoticeList(int page) async {
    return await DioUtil().request(ApiServer.POST_NOTICE,
        method: DioMethod.post,
        data: FormData.fromMap({"page": page, "page_size": 20}));
  }

  static Future<DioResponse<VideoEntity>> reqVideoList(
      int page, String type_id) async {
    return await DioUtil().request(ApiServer.POST_AIRCLE,
        method: DioMethod.post,
        data: FormData.fromMap(
            {"page": page, "page_size": 20, "type_id": type_id}));
  }

  static Future<DioResponse<VideoEntity>> reqVideoListSize(
      int page, int pageSize) async {
    return await DioUtil().request(ApiServer.POST_VIDEO,
        method: DioMethod.post,
        data: FormData.fromMap({"page": page, "page_size": pageSize}));
  }

  static Future<DioResponse<NewsEntity>> reqNewsListSize(int page) async {
    return await DioUtil().request(ApiServer.POST_NEWS,
        method: DioMethod.post,
        data: FormData.fromMap({"page": page, "page_size": 20}));
  }

  static Future<DioResponse<NewsEntity>> reqNewsList(
      int page, String type_id) async {
    return await DioUtil().request(ApiServer.POST_AIRCLE,
        method: DioMethod.post,
        data: FormData.fromMap(
            {"page": page, "page_size": 20, "type_id": type_id}));
  }

  static Future<DioResponse<Object>> reqAuth(
      String full_name,
      String no,
      String bank_name,
      String bank_account,
      String id_card_front,
      String id_card_end,
      String bank_img) async {
    return await DioUtil().request(ApiServer.POST_AUTH,
        method: DioMethod.post,
        data: FormData.fromMap({
          "full_name": full_name,
          "no": no,
          "bank_name": bank_name,
          "bank_account": bank_account,
          "id_card_front": id_card_front,
          "id_card_end": id_card_end,
          "bank_img": bank_img,
        }));
  }

  static Future<DioResponse<FileEntity>> reqFileUpLoad(File file) async {
    return await DioUtil().request(ApiServer.POST_UPLOAD,
        method: DioMethod.post,
        data: FormData.fromMap({
          "file": await MultipartFile.fromFile(file.path, filename: "image.jpg")
        }));
  }

  static Future<DioResponse<Object>> reqUpdateInfo(
      {String? nikname, String? mailbox, String? head_url}) async {
    return await DioUtil().request(ApiServer.POST_UPDATE_USERINFO,
        method: DioMethod.post,
        data: FormData.fromMap(
            {"nikname": nikname, "mailbox": mailbox, "head_url": head_url}));
  }

  static Future<DioResponse<Object>> reqUpdatePsw(
      String new_password, String confirm_password, String code) async {
    return await DioUtil().request(ApiServer.POST_UPDATE_PSW,
        method: DioMethod.post,
        data: FormData.fromMap({
          "new_password": new_password,
          "confirm_password": confirm_password,
          "code": code
        }));
  }

  static Future<DioResponse<BankEntity>> reqBankList() async {
    return await DioUtil()
        .request(ApiServer.POST_BANK_LIST, method: DioMethod.post);
  }

  static Future<DioResponse<Object>> reqBankDelete(String id) async {
    return await DioUtil().request(ApiServer.POST_BANK_DELETE,
        method: DioMethod.post, data: FormData.fromMap({"id": id}));
  }

  static Future<DioResponse<Object>> reqBankAdd(
      String bank_name, String bank_account, String bank_img) async {
    return await DioUtil().request(ApiServer.POST_BANK_ADD,
        method: DioMethod.post,
        data: FormData.fromMap({
          "bank_name": bank_name,
          "bank_account": bank_account,
          "bank_img": bank_img,
        }));
  }

  static Future<DioResponse<RechargeRecordEntity>> reqRechargeRecord(
      int page, int status) async {
    return await DioUtil().request(ApiServer.POST_RECHARGE_LIST,
        method: DioMethod.post,
        data: FormData.fromMap({
          "page": page,
          "page_size": 20,
          "status": status,
        }));
  }

  static Future<DioResponse<Object>> recharge(
      String amount, String recharge_img, String recharge_type,
      {String? user_bank_id}) async {
    print('user_bank_id${user_bank_id}');
    print('recharge_type${recharge_type}');
    return await DioUtil().request(ApiServer.POST_RECHARGE,
        method: DioMethod.post,
        data: FormData.fromMap({
          "amount": amount,
          "recharge_img": recharge_img,
          "recharge_type": recharge_type,
          "user_bank_id": user_bank_id,
        }));
  }

  static Future<DioResponse<RechargeConfigEntity>> rechargeConfig() async {
    return await DioUtil()
        .request(ApiServer.POST_RECHARGE_CONFIG, method: DioMethod.post);
  }

  static Future<DioResponse<Object>> withdraw(
      String amount, String user_bank_id) async {
    return await DioUtil().request(ApiServer.POST_WITHDRAW,
        method: DioMethod.post,
        data:
            FormData.fromMap({"amount": amount, "user_bank_id": user_bank_id}));
  }

  static Future<DioResponse<WithdrawRecordEntity>> reqWithdrawRecord(
      int page, int status) async {
    return await DioUtil().request(ApiServer.POST_WITHDRAW_LIST,
        method: DioMethod.post,
        data: FormData.fromMap({
          "page": page,
          "page_size": 20,
          "status": status,
        }));
  }

  static Future<DioResponse<UsdRecordEntity>> reqUsdRecord(int page) async {
    return await DioUtil().request(ApiServer.POST_USD_LIST,
        method: DioMethod.post,
        data: FormData.fromMap({"page": page, "page_size": 20}));
  }

  static Future<DioResponse<Object>> reqForgetPsw(String phone, String code,
      String new_password, String confirm_password) async {
    return await DioUtil().request(ApiServer.POST_FORGET_PSW,
        method: DioMethod.post,
        data: FormData.fromMap({
          "phone": "phone",
          "code": "code",
          "new_password": "new_password",
          "confirm_password": "confirm_password",
        }));
  }

  static Future<DioResponse<IncomeEntity>> reqIncome() async {
    return await DioUtil()
        .request(ApiServer.POST_INCOME, method: DioMethod.post);
  }

  static Future<DioResponse<KInfoEntity>> reqLastTick(
      int is_last, int type) async {
    var timeArray = ["hour", "3hour", "1day", "3day", "7day"];
    return await DioUtil().request(ApiServer.POST_K_LAST_INFO,
        method: DioMethod.post,
        data: FormData.fromMap(
            {"is_last": is_last, "time_type": timeArray[type]}));
  }

  static Future<DioResponse<VersionBeanEntity>> reqVersion() async {
    return await DioUtil()
        .request(ApiServer.POST_VERSION, method: DioMethod.post);
  }

  static Future<DioResponse<AgreementContainEntity>> reqAgreement() async {
    return await DioUtil()
        .request(ApiServer.POST_AGREEMENT, method: DioMethod.post);
  }

  static Future<DioResponse<ClassifyBeanEntity>> reqClassifyHome(
      String type_id) async {
    return await DioUtil().request(ApiServer.POST_CLASSIFY_HOME,
        method: DioMethod.post,
        data: FormData.fromMap({
          "type_id": type_id,
        }));
  }

  static Future<DioResponse<ClassifyEvaluateBeanEntity>>
      reqClassifyEvaluateHome(String type_id) async {
    return await DioUtil().request(ApiServer.POST_CLASSIFY_HOME,
        method: DioMethod.post,
        data: FormData.fromMap({
          "type_id": type_id,
        }));
  }

  static Future<DioResponse<QuestionEntity>> reqQuestionList() async {
    return await DioUtil()
        .request(ApiServer.POST_QUESTION_LIST, method: DioMethod.post);
  }

  static Future<DioResponse<Object>> reqAddQuestion(List inquiry_option) async {
    return await DioUtil().request(ApiServer.POST_QUESTION_ADD,
        method: DioMethod.post,
        data: FormData.fromMap({"inquiry_option[]": inquiry_option}));
  }

  static Future<DioResponse<ServerEntity>> reqServer() async {
    return await DioUtil().request(ApiServer.POST_LINK, method: DioMethod.post);
  }

  static Future<DioResponse<MoneyAccountCountEntity>> reqMoneyAccount(
      int type, String req_amount) async {
    return await DioUtil().request(ApiServer.POST_COMPUTUE_AMOUNT,
        method: DioMethod.post,
        data: FormData.fromMap({"type": type, "req_amount": req_amount,"req_amount_type":type==1?"USD":"RMB"}));
  }
}
